﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using static System.Net.WebRequestMethods;

namespace OurMemory
{
    public partial class FormEditHM : Form
    {
        private readonly HappyMemoriesServices service = new HappyMemoriesServices();
        private Guid id;
        public FormEditHM()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 从上级窗体导入id
        /// </summary>
        /// <param name="id"></param>
        public FormEditHM(Guid id)
        {
            InitializeComponent();
            var item = service.GetById(id);
            if (item != null)
            {
                textStory.Text =item.Story;
                dTP.Value=item.Date;
                textPhoto.Text = item.Photo;
                textRecorder.Text = item.Recorder;
                textFeelings.Text=item.Feelings;
                this.id = id;
            }
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void FormEditHM_Load(object sender, EventArgs e)
        {

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            HappyMemoriesEditModel model = new HappyMemoriesEditModel()
            {
                Id = this.id,
                Story = textStory.Text,
                Date = dTP.Value.Date,
                Photo = textPhoto.Text,
                Recorder = textRecorder.Text,
                Feelings = textFeelings.Text,
            };
            service.Edit(model);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
